package mqLog

import (
	"duanju-mq/pkg/app"
	"duanju-mq/pkg/config"
	"os"
)

var (
	logFileDir = config.String("logFile.logDir", "../log/mqData", "raw log dir")
)

func init() {
	app.OnStart(func() {
		app.AsyncSafe(createCrontab)
	})
}

func WriteLog(s string) {
	WriteLogByIndex(0, s)
}
func WriteLogByIndex(index int, s string) {
	listLen := len(logFileList)
	if listLen == 0 {
		return
	}
	if listLen < index {
		index = 0
	}
	logFileList[index].WriteLog(s)
}
func PathExists(path string) (bool, error) {
	_, err := os.Stat(path)
	if err == nil {
		return true, nil
	}
	if os.IsNotExist(err) {
		return false, nil
	}
	return false, err
}
